/**
 * Created by dale on 2017/8/21.
 */

$(document).ready(function () {


    var form = new xhForm($('#xh_form'));
    form.parse();



    var iNodeId= xhTool.getQuery('iNodeId');
    $("#cc2").combotree({
        onBeforeSelect: function (node) {
            
            if (!$("#cc2").combotree("tree").tree('isLeaf', node.target)) {
                $('#cc2').combotree("clear");
                return false;
            }
        }
    });

    $("#cc4").combotree({
        onBeforeCheck: function (node) {
            if (!$("#cc4").combotree("tree").tree('isLeaf', node.target)) {
                return false;
            }
        }
    });

    if(iNodeId!=null){
        $('[name="sNodeName"]').attr('readonly','readonly');
        form.fill(nodeData);
        $('#cc1').combotree('setValue', nodeData['sExcuteDeps']);
        $('#cc2').combotree('setValue', nodeData['sExcuteIds']);
        $('#cc3').combotree('setValues', nodeData['sRelatDeps']);
        $('#cc4').combotree('setValues', nodeData['sRelatIds']);
    }else {
        var iTPId=xhTool.getQuery('iTPId');
        $('[name="iTPId"]').val(iTPId);
        $('[name="iSort"]').parent().parent().hide();
    }


    $('#bt_modal_confirm',parent.document).click(function () {
        $('[name="sExcuteDeps"]').val($('#cc1').combotree("getValue"));
        $('[name="sExcuteIds"]').val($('#cc2').combotree("getValue"));
        $('[name="sRelatDeps"]').val($('#cc3').combotree("getValues"));
        $('[name="sRelatIds"]').val($('#cc4').combotree("getValues"));
        form.submit('bpm/template/saveNode',{},function (data) {
            window.top.xhTop.getActiveFrame().obj.table.treegrid('reload');
            window.top.xhTop.closeModal();
        });
    });

    // modalBind.bindClick();



});